module two {
	export class JewelryPage extends BaseComponent {
		public constructor() {
			super("JewelryPage");
		}

		public jeInfo: two.JewelryInfo;
		public btn_back: eui.Button;
		public btn_share: eui.Button;
		public btn_unlock: eui.Button;
		public btn_light: eui.Button;
		public btn_buy: eui.Button;
		public btn_zan: eui.Button;
		public btn_zan2: eui.Button;
		public txt_zan: eui.Label;

		private starId: string;

		protected created(): void {
			super.created();

			two.addTap(this.btn_back, () => {
				two.changePage("map");

				one.monitor.emit("onHideJewelry", { id: this.starId });
			})

			two.addTap(this.btn_unlock, () => {
				let box = new UnlockConfirmBox();
				box.once("onOK", () => {
					let code = this.jeInfo.getCurrentJewelryCode();
					if (!code) {
						code = User_getMyJewelryProxy.getInstance().getJewerlyCodeByStar(this.starId);
					}
					User_relieveJewelryProxy.getInstance().send({
						id: code
					}, (data) => {
						if (data.code == 0) {
							this.resetPage();
						}
					});
				}, null);
				two.showBox(box, 0, true);
			})

			two.addTap(this.btn_zan2, () => {
				User_attontionJewelryProxy.getInstance().send({
					id: this.starId
				}, (data) => {
				});
			})

			two.addTap(this.btn_buy, () => {
				openPlatUrl();
			})

			two.addTap(this.btn_light, () => {
				two.scan();
			})
			two.addTap(this.btn_share, () => {
				if (User_getMyJewelryProxy.getInstance().getJewerlyCodeByStar(this.starId)) {
					// let page = two.changePage("share") as SharePage;
					// page.resetJewelry(this.jeInfo.getCurrentJewelryId());

					openStar(this.jeInfo.getCurrentJewelryId());
				}
				else {
					let page = two.changePage("share_open") as ShareOpenPage;
					page.resetStarId(this.starId, false);
				}
			})
		}

		private resetPage(): void {
			let info = User_getJewelryProxy.getInstance().getJewelryInfo(this.starId);
			this.btn_unlock.visible = false;
			this.btn_light.visible = false;

			if (User_getMyJewelryProxy.getInstance().getJewerlyCodeByStar(this.starId)) {
				this.btn_unlock.visible = true;
			}
			else {
				this.btn_light.visible = true;
			}

			this.btn_zan.visible = info.isAttention;
			this.btn_zan2.visible = !info.isAttention;

			this.txt_zan.text = info.attention + "";

			this.jeInfo.resetStarId(this.starId);

			let starCfg = StarConfig.getConfigById(this.starId);
			this.btn_buy.label = `拥有${starCfg.name}`;

			two.shareJepage(true, this.starId);

			this.btn_share.visible = !!User_getMyJewelryProxy.getInstance().getJewerlyCodeByStar(this.starId);
		}

		refreshApi(api: string): void {
			super.refreshApi(api);

			switch (api) {
				case "User_getJewelry":
					this.resetPage();

					break;
			}
		}

		refreshData(type: string, data: any): void {
			super.refreshData(type, data);

			switch (type) {
				case "onInitData":
					this.starId = data.id;
					this.resetPage();
					break;
			}
		}
	}

	two.setClassMap("jewelry", "two.JewelryPage");
}